package com.cnap.controller;

import com.cnap.CnapApplicationTests;
import com.cnap.model.file.MergeReq;
import com.cnap.model.file.PatchRes;
import com.cnap.model.file.UploadPatchReq;
import com.cnap.model.progress.ProgressVO;
import com.cnap.service.FileService;
import com.cnap.service.ProgressService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.nio.charset.StandardCharsets;

/**
 * <类文件描述>
 *
 * @author xc
 **/
class FileControllerTest extends CnapApplicationTests {

    @Autowired
    private FileController fileController;
    @MockBean
    private FileService fileService;
    @MockBean
    private ProgressService progressService;
    @Test
    void uploadPatch() {
        UploadPatchReq req = new UploadPatchReq();
        MultipartFile multipartFile = new MockMultipartFile("test.zip", "123".getBytes(StandardCharsets.UTF_8));

        Mockito.when(fileService.uploadPatch(req, multipartFile)).thenReturn(new PatchRes());

        Assertions.assertDoesNotThrow(()->{
            fileController.uploadPatch(req, multipartFile);
        });
    }

    @Test
    void mergePatch() {
        MergeReq req = new MergeReq();
        Mockito.doNothing().when(fileService).mergePatchFile(req);

        Assertions.assertDoesNotThrow(()->{
            fileController.mergePatch(req);
        });
    }

    @Test
    void queryProgress() {
        ProgressVO progressVO = new ProgressVO();
        Mockito.when(progressService.getProgressByApplicationId("appId")).thenReturn(progressVO);

        Assertions.assertDoesNotThrow(()->{
            fileController.queryProgress("appId");
        });
    }
}